﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web.Script.Serialization;
using TestWSTMS.WSVDC3;

namespace TestWSTMS
{
    public partial class Form1 : Form
    {
        public static WSVDC3.ServiceInCa ws3InCa { get; set; } 
        public Form1()
        {
            InitializeComponent();

            //GetAllInfoCa();
            //InsertCA();
            //InserCaGH();
            InserCustomer();
        }

        public void GetAllInfoCa()
        {
            ws3InCa = new ServiceInCa();
            WSVDC3.AuthenticationHeader objAuthSoapHeader = new WSVDC3.AuthenticationHeader();
            objAuthSoapHeader.UserName_Secur = "vdc3";
            objAuthSoapHeader.Password_Secur = "vdc3#123456@";

            ws3InCa.AuthenticationHeaderValue = objAuthSoapHeader;
            textBox1.Text = ws3InCa.GetCustomerCA().Rows[0][0].ToString();
        }

        //public void InserCustomer(InsertCustomerModel customerInfo)
        public void InserCustomer()
        {
            InsertCustomerModel cus1 = new InsertCustomerModel();

            JavaScriptSerializer jss = new JavaScriptSerializer();

            cus1.TEN_CONG_TY = "Cong ty abc";
            cus1.DIA_CHI_GPKD = "testdia chi";
            cus1.DIA_CHI_XUAT_HOA_DON = "test dia chi gui hoa don";
            cus1.DT_CTY = "0983024494";
            cus1.FAX_CTY = "sadsa";
            cus1.GHI_CHU = "sadsa";
            cus1.MA_DOI_TUONG = "DNTN";
            cus1.MA_LINH_VUC_HOAT_DONG = null;
            cus1.MA_LOAI_CONG_TY = null;
            cus1.MA_LOAI_KHACH_HANG = null;
            cus1.MA_SO_THUE = "2334322";
            cus1.MA_TINH = null;
            cus1.NGAY_THANH_LAP_CONG_TY = DateTime.Now;
            cus1.QUAN = "";
            string jsonobject = jss.Serialize(cus1);

            //Goi webservice
            ws3InCa = new ServiceInCa();
            WSVDC3.AuthenticationHeader objAuthSoapHeader = new WSVDC3.AuthenticationHeader();
            objAuthSoapHeader.UserName_Secur = "vdc3";
            objAuthSoapHeader.Password_Secur = "vdc3#123456@";

            ws3InCa.AuthenticationHeaderValue = objAuthSoapHeader;
            string strResult = ws3InCa.ExtensionCA(jsonobject);

            //nhan ket qua tra ve va xu ly
            MessageExten mess = jss.Deserialize<MessageExten>(strResult);
            if (mess.Result == 1) // thanh cong
            {
                //xu ly khi thang cong
            }
            else if (mess.Result == 0) // thất bai
            {
                MessageBox.Show(mess.Message);
            }
        }

        public void InsertCA()
        {

            InserCAModel cus1 = new InserCAModel();
            cus1.MA_SO_THUE = "12345678901";
            cus1.GHI_CHU = "sadsa";
            cus1.GIOI_TINH_NLH = true;
            cus1.GOI_NAM = 12;
            cus1.DO_DAI_KHOA = 1024;
            cus1.KM_CUOC = 0;
            cus1.THANG_KHUYEN_MAI = null;
            cus1.KM_KHAC = "0";
            cus1.KY_SO = true;
            cus1.MA_CHUC_VU = "TL";
            cus1.MA_DAI_LY = "admin";
            cus1.MA_HINH_THUC_THANH_TOAN = "01";
            cus1.MA_NHAN_DIEN_GOI_CUOC = "OID Standard";
            cus1.EMAIL_NGUOI_LH = "nvloc@gmail.com";
            cus1.EMAIL = "nvloc@yahoo.com";
            cus1.CMND = "0101010101";
            cus1.DIA_CHI_LIEN_LAC = "24 le thanh ton";
            cus1.DT_NGUOI_LH = "0905300577";
            cus1.NGAN_HANG = "Viet Com Bank";
            cus1.NGAY_GUI_KH = null;
            cus1.NGAY_KY_HD = DateTime.Now;
            cus1.NGAY_NHAP = DateTime.Now;
            cus1.NGUOI_KY = "Tran Ly";
            cus1.NGUOI_LIEN_HE = "Nguyen Van B";
            cus1.SO_HD = "123321";
            cus1.TAI_KHOAN = "01244567777";
            cus1.UserName_NHAN_VIEN = "admin";
            cus1.VAT = 10;
            cus1.XAC_THUC = true;
            cus1.DA_XUAT_HOA_DON = DateTime.Now;
            cus1.BAO_VE_EMAIL = true;
            cus1.KY_SO = true;
            cus1.XAC_THUC = true;


            //Tao doi tuong chuyen doi Json
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string jsonobject = jss.Serialize(cus1);

            //Goi webservice
            ws3InCa = new ServiceInCa();
            WSVDC3.AuthenticationHeader objAuthSoapHeader = new WSVDC3.AuthenticationHeader();
            objAuthSoapHeader.UserName_Secur = "vdc3";
            objAuthSoapHeader.Password_Secur = "vdc3#123456@";

            ws3InCa.AuthenticationHeaderValue = objAuthSoapHeader;
            string strResult = ws3InCa.InsertCAGen(jsonobject);

            //nhan ket qua tra ve va xu ly
            MessageExten mess = jss.Deserialize<MessageExten>(strResult);
            if (mess.Result == 1) // thanh cong
            {
                //xu ly khi thang cong
                MessageBox.Show("insert success");
            }
            else if (mess.Result == 0) // thất bai
            {
                MessageBox.Show(mess.Message);
            }
        }

        public void InserCaGH()
        {
            DV_CA_InsertCertInfoModel gh = new DV_CA_InsertCertInfoModel();
            gh.SO_GIAY_CN = (int?)null;
            gh.SO_HD = "123321";
            gh.ACCOUNT = "";
            gh.USERNAME = "OIDDNG12345678901";
            gh.NGAY_NGHIEM_THU = DateTime.Now;
            gh.SERIAL_NUMBER = "00 00 00 00 00 00 00 00 00 00 00 00";
            gh.SUBJECT_DN = "0.9.2342.19200300.100.1.1 = MST:4201138950 CN = CÔNG TY TNHH ĐẠI LÝ TÀU BIỂN VŨ LONG";
            gh.MA_NHAN_DIEN_GOI_CUOC = "OID Standard";
            gh.GOI_NAM = 24;
            gh.DO_DAI_KHOA = 1024;
            gh.KM_CUOC = 0;
            gh.NGAY_KICH_HOAT = DateTime.Now;
            gh.NGAY_HET_HAN = DateTime.Now.AddYears(2);
            gh.NGAY_GIAO_KTTC = DateTime.Now;
            gh.NGAY_GIAO_DVKH = DateTime.Now;
            gh.BAO_VE_EMAIL = true;
            gh.KY_SO = true;
            gh.XAC_THUC = true;
            gh.MA_DAI_LY = null;  //nullable
            gh.USERNAME_NGUOI_THUC_HIEN = "admin";
            gh.VAT = 10;
            gh.NGAY_NHAN_HS = DateTime.Now;
            gh.GHI_CHU = "";
            gh.THANG_KHUYEN_MAI = 0;
            //Tao doi tuong chuyen doi Json
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string jsonobject = jss.Serialize(gh);

            //Goi webservice
            ws3InCa = new ServiceInCa();
            WSVDC3.AuthenticationHeader objAuthSoapHeader = new WSVDC3.AuthenticationHeader();
            objAuthSoapHeader.UserName_Secur = "vdc3";
            objAuthSoapHeader.Password_Secur = "vdc3#123456@";

            ws3InCa.AuthenticationHeaderValue = objAuthSoapHeader;
            //string strResult = ws3InCa.InsertCustomer(jsonobject);
            string strResult = ws3InCa.ExtensionCA(jsonobject);

            //nhan ket qua tra ve va xu ly
            MessageExten mess = jss.Deserialize<MessageExten>(strResult);
            if (mess.Result == 1) // thanh cong
            {
                //xu ly khi thang cong
            }
            else if (mess.Result == 0) // thất bai
            {
                MessageBox.Show(mess.Message);
            }
        }
    }
}
